import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from "../views/HomeView.vue"

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: "/home"
  },
  {
    path: '/home',
    name: "home",
    component: HomeView,
    meta:{
      keep:true,
    }
  },
  {
    path: '/myhome',
    name: 'myhome',
    component: () => import('../views/MyHome.vue'),

  },
  {
    path: '/shoppingcart',
    name: 'shoppingcart',
    component: () => import('../views/ShoppingCart.vue'),
   
  },
  {
    path: '/worthbuying',
    name: 'worthbuying',
    component: () => import('../views/WorthBuying.vue'),
  },
  {
    path: '/category',
    name: 'category',
    component: () => import('../views/CategoryView.vue'),
  },
  {
    path: '/bookslist',
    name: 'bookslist',
    component: () => import('../views/BooksList.vue'),
  },
  {
    path: '/detail2',
    name: 'detail2',
    component: () => import('../views/DetailView2.vue'),
  },
  {
    path: '/detail',
    name: 'detail',
    component: () => import('../views/DetailView.vue'),
  },
  {
    path: '/ordersettlement',
    name: 'ordersettlement',
    component: () => import('../views/OrderSettlement.vue'),
  },
  {
    path: '/addressbook',
    name: 'addressbook',
    component: () => import('../views/AddressBook.vue'),
  },
  {
    path: '/addaddress',
    name: 'addaddress',
    component: () => import('../views/AddAddress.vue'),
  },
  {
    path: '/orders',
    name: 'orders',
    component: () => import('../views/ordersView.vue'),
  },
  {
    path: '/loginUser',
    name: 'loginUser',
    component: () => import('../views/LoginView.vue'),
  },
  {
    path: '/registered',
    name: 'registered',
    component: () => import('../views/registeredView.vue'),
  },
  {
    path: '/reading',
    name: 'reading',
    component: () => import('../views/readingView.vue'),
  },
  // {
  //   path: '/userinfo',reading
  //   name: 'userinfo',
  //   component: () => import('../views/userinfoView.vue'),
  //   // 独享路由守卫
  //   beforeEnter:(to,from,next)=>{
  //     let token = window.localStorage.getItem("token");
  //     // 判断是否登录
  //     if(!token){
  //       next("/login");
  //       return;
  //     }else{
  //       next();
  //     }
  //   }
  // },

]

// 注意:解决路由跳转问题
// const originalPush = VueRouter.prototype.push
// VueRouter.prototype.push = function push(location){
//   return originalPush.call(this,location).catch(err=>err);
// }



const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes,
  linkActiveClass: "active",
})

// 配置全局路由守卫
// 用户必须登录才进入  必须登录才可以进入
// router.beforeEach((to,from,next)=>{
//   let token = window.localStorage.getItem("token");
//   // 登录界面判断
//   if(to.path == "/login"){
//       next();
//       return;
//   }else{ //判断是否登录
//     if(!token){
//       next("/login");//进入登录页面
//       return;
//     }else{
//       next();//执行下一个路由
//     }
//   }
// })



export default router
